<?php
/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: profile.php 2009-11-3 $ 
*/

if(!defined('IN_UCHOME')) {
	exit('Access Denied');
}

include_once(S_ROOT.'./source/function_cp.php');
include_once(S_ROOT.'./site/libs/func_util.php');
include_once(S_ROOT.'./site/libs/func_model.php');


$page = empty($_GET['page'])?1:intval($_GET['page']);
if($page<1) $page=1;

// 导航栏
$fid = empty($_GET['fid'])?0:intval($_GET['fid']);

$theurl = "site.php?ac=show&fid=".$fid;

if (!$fid)
{
	showmessage('enter_the_space', 'index.php', 0);
}

if ($fid && !array_key_exists($fid, $_SGLOBAL['profield']))
{
	showmessage('error_404');
}

$li_name  = get_li_name_by_fid($fid);
$top_name = get_parent_name_by_fid($fid);
$top_fid = get_parent_name_by_fid($fid, "id");

//if ($top_fid != $fid)

//$threadlist = get_hot_wthread_list($fid);

//$hotspotlist = getspots($fid);

/*
$parent_fid = $_SGLOBAL['profield'][$fid]['parentid'];
$parent_fid_txt = '';
if (array_key_exists($parent_fid, $_SGLOBAL['profield']))
	$parent_fid_txt = "&gt;&gt; <a href=\"site.php?ac=profile&op=list&fid=".$_SGLOBAL['profield'][$parent_fid]['fieldid']."\">" . $_SGLOBAL['profield'][$parent_fid]['title'] . "</a>";
*/
//$parent_fid_txt = gen_nav_txt_by_id($fid);
//$nav_area = $parent_fid_txt . " &gt;&gt; " .  $_SGLOBAL['profield'][$fid]['title'];

$sub_list = array();

foreach($_SGLOBAL['profield'] as $p)
{
	if ($p['parentid'] == $top_fid)
	{
		$sub_list[] = $p;
	}
}
 
//    $hotproflist = getprofs($fid);

$perpage = 32;
$start = ($page-1)*$perpage;
//检查开始数
ckstart($start, $perpage);


if($fid){
	foreach ($_SGLOBAL['profield'] as $value) {
		if ($value['fieldid'] == $fid && $value['parentid']) {
			$type = "and field.fieldid = $fid";
			$title1 = $value['title'];
			foreach ($_SGLOBAL['profield'] as $value2) {
				if ($value2['fieldid'] == $value['parentid']){
					$title2 = $value2['title'];
				}
			}
		} elseif ($value['fieldid'] == $fid && !$value['parentid']) {
			$title1 = $value['title'];
			foreach ($_SGLOBAL['profield'] as $value) {
				if ($value['parentid'] == $fid){
					$ids[] = $value['fieldid'];
				}
			}
			if($ids)
				$ids = implode(",", $ids);
			else
				$ids = '0';
			$type = "and field.fieldid in ($ids)";
			$theurl = "site.php?ac=show&fid=$fid";
		}
	}
}
$list = $tagids = array();

$count = $_SGLOBAL['db']->result($_SGLOBAL['db']->query("SELECT COUNT(*) FROM ".tname('mtag')." field WHERE 1=1 $type and tagtype = '1'"),0);
if($count) {

	$sql = "SELECT field.* FROM ".tname('mtag')." field
		WHERE field.tagtype=1 $type LIMIT $start,$perpage"; 

	$query = $_SGLOBAL['db']->query($sql);
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		realname_set($value['uid'], $value['username']);
		if(empty($value['pic'])) {
			$value['pic'] = 'image/nologo.jpg';
		} else {
			$value['pic'] = file_exists($value['pic'].'.65.jpg') ? $value['pic'].'.65.jpg' : $value['pic'];
		}
		if($value['grade']>-2) {
			$tagids[$value['tagid']] = $value['tagid'];//已经批准的群组
		}
		$list[] = $value;
	}
}

//分页
$multi = multi($count, $perpage, $page, $theurl);

//最新话题
/*
$threadlist = array();
if($tagids) {
	$query = $_SGLOBAL['db']->query("SELECT main.*,field.tagname,field.membernum,field.fieldid FROM ".tname('thread')." main
		LEFT JOIN ".tname('mtag')." field ON field.tagid=main.tagid
		WHERE main.tagid IN (".simplode($tagids).")
		ORDER BY main.lastpost DESC
		LIMIT 0,10");
	while ($value = $_SGLOBAL['db']->fetch_array($query)) {
		realname_set($value['uid'], $value['username']);
		$threadlist[] = $value;
	}
}
*/
realname_get();

include_once template('site/tpl/profile_list');
exit;


?>
